<template>
	<view class="page">
		<view class="novel" v-if="item.readHistory" v-for="(item,index) in items" :key="item.id" @tap="novelTap(item)">
			<view class="content">
				<image class="default-cover cover" :data-cover="item.cover?'':'暂无封面'" :src="item.cover"
					mode="scaleToFill"></image>
				<view class="right">
					<view class="title">{{item.title}}</view>
					<view class="author-cat">
						{{item.author}}
						<text v-if="item.cat" class="split">·</text>
						{{item.cat}}
						<text v-if="item.wordCount" class="split">·</text>
						{{item.wordCount}}
					</view>
					<view class="desc">读至：{{item.curChapter?`${item.curChapter}`:'[未开始]'}}</view>
					<view v-if="item.longIntro" class="desc">{{item.longIntro}}</view>
				</view>
			</view>
		</view>
		<view v-if="items.filter(item => item.readHistory).length===0" class="noList">暂无记录</view>
	</view>
</template>

<script>
	import {
		mapGetters,
		mapMutations
	}
	from 'vuex'
	export default {
		data() {
			return {}
		},
		computed: {
			items: {
				get() {
					return this.$store.getters.get_readHistory
				},
				set(val) {
					this.set_readHistory(val)
				}
			}
		},
		onNavigationBarButtonTap(e) {
			// 清空按钮
			if (e.index === 0) {
				let tData = this.items
					.filter(item => item.bookshelf)
					.map(item => {
						item.readHistory = false
						return item
					})
				this.items = tData
			}
		},
		methods: {
			...mapMutations(['set_readHistory']),
			novelTap(item) {
				uni.navigateTo({
					url: '/pages/public/bookDetail?id=' + item._id
				})
			},
		}
	}
</script>
<style lang="scss">
	.novel {
		padding: 30rpx;

		.content {
			display: flex;
			justify-content: flex-start;

			.cover {
				width: 120rpx;
				height: 160rpx;
			}

			.right {
				width: 570rpx;
				padding-left: 30rpx;
				box-sizing: border-box;

				.title {
					// font-size: 28rpx;
					font-weight: bold;
				}

				.author-cat {
					color: #999;
					font-size: 26rpx;
					height: 40rpx;
					line-height: 40rpx;

					.split {
						padding: 0 16rpx;
					}
				}

				.desc {
					color: #999;
					font-size: 26rpx;
					height: 40rpx;
					line-height: 40rpx;

					overflow: hidden;
					text-overflow: ellipsis;
					word-break: break-all;
					display: -webkit-box;
					-webkit-line-clamp: 1;
					-webkit-box-orient: vertical;
				}
			}
		}
	}

	.novel+.novel {
		margin-top: 10rpx;
		border-top: 1px solid #f8f8f8;
	}

	.noList {
		text-align: center;
		margin-top: 100px;
	}
</style>
